//
//  StartScene.m
//  PlaneWar2
//
//  Created by HappyMilk 02 on 2017/4/6.
//  Copyright © 2017年 HappyMilk 02. All rights reserved.
//

#import "StartScene.h"

@implementation StartScene

- (CGFloat )random{
    return (CGFloat)((CGFloat)arc4random() / 0xFFFFFFFF);
}
- (CGFloat )randomeBy:(CGFloat )min and:(CGFloat )max{
    return [self random] * (max - min) + min;
}

- (void)didMoveToView:(SKView *)view{
    
    SKTexture *texture = [SKTexture textureWithImage:[UIImage imageNamed:@"background"]];
    SKSpriteNode *background = [SKSpriteNode spriteNodeWithTexture:texture size:self.size];
    background.position = CGPointMake(self.size.width/2, self.size.height/2);
    background.zPosition = 0;
    [self addChild:background];
    
    [self runAction:[SKAction repeatActionForever:[SKAction sequence:@[[SKAction runBlock:^{
        [self addClouds];
    }],[SKAction waitForDuration:4.0]]]]];
    
    SKSpriteNode *cloud = [SKSpriteNode spriteNodeWithImageNamed:@"yun"];
    cloud.position = CGPointMake(self.size.width*[self random], self.size.height);
    cloud.zPosition = 1;
    [self addChild:cloud];
}

- (void)addClouds{
    
    SKSpriteNode *cloud = [SKSpriteNode spriteNodeWithImageNamed:@"yun"];
    cloud.position = CGPointMake(self.size.width*[self random], self.size.height);
    cloud.zPosition = 1;
    [self addChild:cloud];
    
    SKAction *move = [SKAction moveToY:0.0 duration:20];
    SKAction *moveDone = [SKAction removeFromParent];
    [cloud runAction:[SKAction sequence:@[move,moveDone]]];
}


@end
